# JavaScript Document for public functions
Number::toMoney = -> ''+this.toFixed(2)

#----------String------------
String::endsWith = (str)->
  return false if not str?
  if(@substring(@length - str.length) is str)
    return true
  else
    return false
  return true

String::startsWith = (str)->
  return false if not str?
  if @substr(0, str.length) == str
    return true
  else
    return false
  return true

String::contains = (str)->
  startChar = str.substring(0, 1)
  strLen = str.length
  for j in [0...@length - strLen + 1]
    if @charAt(j) == startChar
      if @substring(j, j+strLen) == str
        return true
  return false

String::replaceAll = (reallyDo, replaceWith, ignoreCase)->
  if !RegExp::isPrototypeOf reallyDo
    return @replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith)
  else
    return @replace(reallyDo, replaceWith)

String::trim = -> @replace(/^\s\s*/, '').replace(/\s\s*$/, '')

#-----------Array------------
Array::indexOf = (txt)->
  for i in [0...@length]
    if @[i] == txt
      return i
  return -1;

Array::each = (callback)->
  for i in [0...@length]
    callback.call(@, @[i])

# var myParam = getQueryString()["myParam"];
getQueryString = ->
  result = {}
  queryString = location.search.substring(1)
  re = /([^&=]+)=([^&]*)/g
  while m = re.exec(queryString)
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2])
  return result
